package com.cloudcentral.util;

import java.util.regex.Pattern;

/**
 * Create by WEI
 * 2022-02-01 15:39:44
 */
public class PatternUtils {
  /**
   * 正则表达式：验证平台代码
   */
  public static final String REGEX_PLATFORM_CODE = "^[a-z]{1,20}$";
  /**
   * 正则表达式：验证账户
   */
  public static final String REGEX_USERNAME = "^[a-zA-Z|\\u4e00-\\u9fa5]{2,30}$";
  /**
   * 正则表达式：验证密码
   */
  public static final String REGEX_PASSWORD = "^[\\w\\.]{6,18}$";
  /**
   * 正则表达式：验证手机号码
   */
  public static final String REGEX_PHONE = "^((17[0-9])|(14[0-9])|(13[0-9])|(15[^4,\\D])|(18[0,5-9])|(19[0,5-9]))\\d{8}$";
  /**
   * 正则表达式：验证身份证号码
   */
  public static final String REGEX_IDCARD = "(^\\d{18}$)|(^\\d{15}$)";
  /**
   * 正则表达式：验证菜单代码
   */
  public static final String REGEX_MENU_CODE = "^[a-zA-Z]{2,30}$";
  /**
   * 正则表达式：验证权限操作指令
   */
  public static final String REGEX_AUTH_ACTION = "^[A-Z][a-zA-Z]+$";

  /**
   * 校验平台代码
   *
   * @param value
   * @return
   */
  public static Boolean isPlatformCode(String value) {
    return Pattern.matches(REGEX_PLATFORM_CODE, value);
  }

  /**
   * 校验账户
   *
   * @param value
   * @return
   */
  public static Boolean isUsername(String value) {
    return Pattern.matches(REGEX_USERNAME, value);
//    return true;
  }

  /**
   * 校验密码
   *
   * @param value
   * @return
   */
  public static Boolean isPassword(String value) {
    return Pattern.matches(REGEX_PASSWORD, value);
  }

  /**
   * 校验手机号码
   *
   * @param mobile
   * @return
   */
  public static Boolean isPhone(String mobile) {
    return Pattern.matches(REGEX_PHONE, mobile);
//    return true;
  }

  /**
   * 校验身份证号码
   *
   * @param idcard
   * @return
   */
  public static Boolean isIDCard(String idcard) {
    return Pattern.matches(REGEX_IDCARD, idcard);
  }

  /**
   * 校验菜单路径
   *
   * @param menuPath
   * @return
   */
  public static Boolean isMenuCode(String menuPath) {
    return Pattern.matches(REGEX_MENU_CODE, menuPath);
  }

  /**
   * 校验权限操作指令
   *
   * @param authAction
   * @return
   */
  public static Boolean isAuthAction(String authAction) {
    return Pattern.matches(REGEX_AUTH_ACTION, authAction);
  }

  /**
   * 根据自定义正则表达式进行校验
   *
   * @param regex
   * @param value
   * @return
   */
  public static Boolean is(String regex, String value) {
    return Pattern.matches(regex, value);
  }
}